import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, OneToMany, OneToOne, } from 'typeorm';
import { Friendships } from './friendships.entity'
import { Article } from './article.entity'
import { ArticleMoment } from './articleMoment.entity'
import {ArticleLike} from './articleLike.entity'
import {ArticleCollect} from './articleCollect.entity'

@Entity()
export class User {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @Column()
    name: string;

    @Column()
    email: string;

    @Column({ nullable: true })
    phone: string | null;

    @Column({ default: -1 })
    sex: number;

    @Column({ nullable: true })
    age: number | null;

    @Column({ nullable: true })
    birthday: string | null;

    @Column({ nullable: true })
    avatar: string | null;

    @Column({ nullable: true })
    address: string | null;

    @Column({ nullable: true })
    desc: string | null;

    @Column({ select: false })
    password: string;

    @Column({ default: 1 })
    isActive: boolean;

    @Column({ default: 1 })
    role: number;

    @Column({ default: false, select: false })
    isDelete: boolean;

    @CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)', select: false })
    createdAt: Date;

    @CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)', select: false })
    updatedAt: Date;

    // 关联好友表
    @OneToMany(() => Friendships, friendships => friendships.user)
    friendshipsUser: Friendships[]

    // 关联好友表
    @OneToMany(() => Friendships, friendships => friendships.friend)
    friendshipsFriend: Friendships[]

    // 关联article表
    @OneToMany(() => Article, article => article.author)
    articleUser: Article[]

    
    @OneToMany(() => ArticleMoment, articleMoment => articleMoment.author)
    articleCommentUser: ArticleMoment[]
    
    @OneToMany(() => ArticleMoment, articleMoment => articleMoment.replayUser)
    articleCommentReplayUser: ArticleMoment[]

    @OneToMany(()=>ArticleLike,articleLike=>articleLike.user)
    articleLikeUser:ArticleLike[]

    @OneToMany(()=>ArticleCollect,articleCollect=>articleCollect.user)
    articleCollectUser:ArticleCollect[]
}